<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background-color: #9d89e5;
        }
    </style>
</head>

<body>
    <div></div>
</body>
<script>
    let str = '#';
    for (let i = 1; i <= 6; i++) { //随机获取六个值
        let num = parseInt(Math.random() * 16);
        if (num < 10) {
            str += num;
        } else {
            str += getNum(num);
        }
    }
    console.log(str);
    let div = document.querySelector('div');
    div.style.backgroundColor = str;
    console.log(div);

    function getNum(num) {
        switch (num) {
            case 10:
                return 'a';
                break;
            case 11:
                return 'b';
                break;
            case 12:
                return 'c';
                break;
            case 13:
                return 'd';
                break;
            case 14:
                return 'e';
                break;
            case 15:
                return 'f';
                break;
        }

    }
</script>

</html>